<template>
  <!-- <t-dialog :header="header" :visible.sync="visible" :onClose="closeDialog" :closeOnOverlayClick="false"
    :confirmBtn="null" width="90%" top="5%">
    <div style="height: 60vh"> -->
  <t-tabs size="medium" v-model="tabValue">
    <t-tab-panel value="1" label="基本信息" :destroyOnHide="true" :class="[reviewOpen ? 'tab-full-panel' : 'tab-panel']">
      <t-form labelWidth="200px" colon>
        <t-row style="align-items: stretch" :gutter="14">
          <t-col :span="12">
            <t-card class="step-card" size="small" title="基本信息">
              <t-row style="align-items: stretch" :gutter="14">
                <t-col :span="6">
                  <t-form-item label="平台名称" name="name">
                    {{ data.name }}
                  </t-form-item>
                  <t-form-item label="平台类型" name="platformCategory">
                    {{ data.platformCategory | filterByDict(dict.type.platform_category) }}
                  </t-form-item>
                  <t-form-item label="技术领域" name="technicalField">
                    {{ data.technicalField | filterByDict(dict.type.platform_technical_field) }}
                  </t-form-item>
                  <t-form-item label="组建方式" name="constructionMode">
                    {{ data.constructionMode | filterByDict(dict.type.construction_mode) }}
                  </t-form-item>
                  <t-form-item label="申报方式" name="declarationMethod">
                    {{ data.declarationMethod | filterByDict(dict.type.declaration_method) }}
                  </t-form-item>
                  <t-form-item label="申报日期" name="declarationDate">
                    {{ data.declarationDate }}
                  </t-form-item>
                  <t-form-item label="主管部门" name="manageDept">
                    {{ data.manageDept }}
                  </t-form-item>
                </t-col>
                <t-col :span="6">
                  <t-form-item label="依托单位" name="deptName">
                    {{ currentDeptName }}
                  </t-form-item>
                  <t-form-item label="通讯地址" name="address">
                    {{ data.address }}
                  </t-form-item>
                  <t-form-item label="邮编" name="postCode">
                    {{ data.postCode }}
                  </t-form-item>
                  <t-form-item label="平台服务行业" name="serviceIndustry">
                    {{ data.serviceIndustry }}
                  </t-form-item>
                  <t-form-item label="平台研究方向所属学科" name="owningSubject">
                    {{ data.owningSubject | filterByDict(dict.type.kjpt_owning_subject) }}
                  </t-form-item>
                  <t-form-item label="项目开始日期" name="startDate">
                    {{ data.startDate }}
                  </t-form-item>
                  <!-- <t-form-item label="平台建设内容" name="intro">
                        {{ data.intro }}
                      </t-form-item> -->
                </t-col>
              </t-row>
              <t-row>
                <t-col :span="12">
                  <t-form-item name="intro" label="平台建设内容">
                    <inner-html :content="data.intro"></inner-html>
                  </t-form-item>
                </t-col>
              </t-row>
            </t-card>
          </t-col>
          <t-col :span="12" style="margin-top: 20px;">
            <t-row style="align-items: stretch" :gutter="14">
              <t-col :span="6">
                <t-card class="step-card" size="small" title="平台联系人">
                  <t-form-item label="姓名" name="platformLinker.name">
                    {{ data.platformLinker.name }}
                  </t-form-item>
                  <t-form-item label="手机号码" name="platformLinker.phone">
                    {{ data.platformLinker.phone }}
                  </t-form-item>
                  <t-form-item label="电子信箱" name="platformLinker.email">
                    {{ data.platformLinker.email }}
                  </t-form-item>
                </t-card>
              </t-col>
              <t-col :span="6">
                <t-card class="step-card" size="small">
                  <template #title>
                    平台主要研究方向：
                  </template>
                  <t-form-item name="researchDirections">
                    <contract-terms ref="contract-terms" v-model="data.researchDirections"
                      :editOpen="false"></contract-terms>
                  </t-form-item>
                </t-card>
              </t-col>
            </t-row>
          </t-col>

        </t-row>

        <t-row style="align-items: stretch" :gutter="14">
          <t-col :span="12">
            <t-card class="step-card" size="small" title="平台负责人">
              <t-row>
                <t-col :span="6">
                  <t-form-item label="姓名" name="platformLeader.name">
                    {{ data.platformLeader.name }}
                  </t-form-item>
                  <t-form-item label="性别" name="platformLeader.sex">
                    {{ data.platformLeader.sex | filterByDict(dict.type.sys_user_sex) }}
                  </t-form-item>
                  <t-form-item label="身份证号" name="platformLeader.idCard">
                    {{ data.platformLeader.idCard }}
                  </t-form-item>
                  <t-form-item label="出生年月" name="platformLeader.birthDate">
                    {{ data.platformLeader.birthDate }}
                  </t-form-item>
                  <t-form-item label="手机号码" name="platformLeader.phone">
                    {{ data.platformLeader.phone }}
                  </t-form-item>
                  <t-form-item label="电子信箱" name="platformLeader.email">
                    {{ data.platformLeader.email }}
                  </t-form-item>
                  <t-form-item label="学历" name="platformLeader.education">
                    {{ data.platformLeader.education | filterByDict(dict.type.education) }}
                  </t-form-item>
                </t-col>
                <t-col :span="6">
                  <t-form-item label="专业" name="platformLeader.majorName">
                    {{ data.platformLeader.majorName }}
                  </t-form-item>
                  <t-form-item label="职务" name="platformLeader.duty">
                    {{ data.platformLeader.duty }}
                  </t-form-item>
                  <t-form-item label="技术职称" name="platformLeader.profTitId">

                    {{ data.platformLeader.profTitId | filterByTree(profTitOptions, children = "children", id =
                      "id", label
                    = "name") }}
                  </t-form-item>


                  <t-form-item label="职称" name="platformLeader.profTit">
                    {{ data.platformLeader.profTit | filterByDict(dict.type.prof_tit) }}
                  </t-form-item>
                  <t-form-item label="所在单位" name="platformLeader.workUnit">
                    <!-- <t-tree-select disabled filterable style="width: 390px" :treeProps="{ keys: { value: 'id' } }"
                      v-model="data.platformLeader.workUnit" :data="deptMenuOptions"
                      placeholder="选择所在单位"></t-tree-select> -->
                    {{ data.platformLeader.workUnit | filterByTree(deptMenuOptions) }}
                  </t-form-item>
                  <t-form-item label="年累计在平台工作时间(月)" name="platformLeader.workMonth">
                    {{ data.platformLeader.workMonth }}
                  </t-form-item>
                </t-col>
              </t-row>
            </t-card>
          </t-col>
        </t-row>


      </t-form>
    </t-tab-panel>
    <t-tab-panel value="2" label="平台主要人员" :destroyOnHide="true" :class="[reviewOpen ? 'tab-full-panel' : 'tab-panel']">
      <t-form colon labelWidth="160px">
        <t-form-item label="" name="">
          <platform-main-member :editOpen="false" :value="stepTwoData"></platform-main-member>
        </t-form-item>
      </t-form>
    </t-tab-panel>
    <t-tab-panel value="3" label="现有仪器及设备一览表（20万元以上）" :destroyOnHide="true"
      :class="[reviewOpen ? 'tab-full-panel' : 'tab-panel']">
      <t-form colon labelWidth="160px">
        <t-form-item label="" name="">
          <platform-device :editOpen="false" :value="stepThreeData"></platform-device>
        </t-form-item>
      </t-form>
    </t-tab-panel>
    <t-tab-panel value="4" label="管理委员会成员" :destroyOnHide="true" :class="[reviewOpen ? 'tab-full-panel' : 'tab-panel']">
      <t-form colon labelWidth="160px">
        <t-form-item label="" name="">
          <platform-manager-member v-model="stepFourData" :editOpen="false"></platform-manager-member>
        </t-form-item>
      </t-form>
    </t-tab-panel>
    <t-tab-panel value="5" label="学术委员会成员" :destroyOnHide="true" :class="[reviewOpen ? 'tab-full-panel' : 'tab-panel']">
      <t-form colon labelWidth="160px">
        <t-form-item label="" name="">
          <platform-study-member v-model="stepFiveData" :editOpen="false"></platform-study-member>
        </t-form-item>
      </t-form>
    </t-tab-panel>
    <t-tab-panel value="6" label="附件" :destroyOnHide="true" :class="[reviewOpen ? 'tab-full-panel' : 'tab-panel']">
      <t-form colon labelWidth="160px">
        <t-form-item label="" name="">
          <t-table row-key="id" :columns="projectFileColumns" :data="projectFileData">
            <template #id="{ row, rowIndex }">
              {{ rowIndex + 1 }}
            </template>
            <template #c1="{ row }">
              <a v-if="row.c3" class="t-button-link" :href="`${file_domain}/${row.c3}`" target="_blank">{{ row.c1
                }}</a>
              <div v-else>{{ row.c1 }}</div>
            </template>
            <template #op="{ row }">
              <div v-for="(item, index) in row.fileLists" :key="index">
                <a class="t-button-link" target="_blank" :href="item.url">
                  {{ item.name }}
                </a>
              </div>
            </template>
          </t-table>
        </t-form-item>
      </t-form>
    </t-tab-panel>
  </t-tabs>
  <!-- </div>

  </t-dialog> -->
</template>

<script>
import { VITE_FILE_DOMAIN } from '@/api/upload'
import { getFiles } from "@/api/common";
import platformBudget from "@/pages/kjpt/platform/components/platform-budget.vue";
import PlatformBackgroundLiterature from "@/pages/kjpt/platform/components/platform-background-literature.vue";
import platformMember from "@/pages/kjpt/components/platform-member.vue";
import platformMemberTechnology from "@/pages/kjpt/components/platform-member-technology.vue";
import InnerHtml from "@/components/InnerHtml/index.vue";
import contractTerms from "./contract-terms.vue";
import platformMainMember from "./platform-main-member.vue";
import PlatformDevice from "./platform-device.vue";
import platformManagerMember from "./platform-manager-member.vue";
import platformStudyMember from "./platform-study-member.vue";
import dayjs from "dayjs";

export default {
  dicts: ["platform_status", "platform_category", "platform_technical_field", "construction_mode", "declaration_method", "kjpt_owning_subject", "kjpt_key_word", "project_type", "subject_classification", "sys_user_sex", "prof_tit", "degree", "education", "duty", "platform_type", "expect_result_type", "platform_level", "research_direction"],
  components: {
    platformBudget,
    PlatformBackgroundLiterature,
    platformMember,
    platformMemberTechnology,
    InnerHtml,
    contractTerms,
    platformMainMember,
    PlatformDevice,
    platformManagerMember,
    platformStudyMember
  },
  props: {
    objId: [String, Number],
    header: String,
    reviewOpen: {
      type: Boolean,
      default: false
    },
    hideInfo: {
      type: Boolean,
      default: false
    }
  },
  data () {
    return {
      dayjs,
      profTitOptions: [],
      deptMenuOptions: [],
      stepTwoData: null,
      stepThreeData: null,
      stepFourData: null,
      stepFiveData: null,
      file_domain: VITE_FILE_DOMAIN,
      projectFileData: [
        {
          id: 1,
          c1: "实验室人员表（依托单位盖章扫描上传）",
          c2: "是",
          moduleKey: "kjptsysryb",
          require: true,
          fileIds: [],
          fileLists: [],
          tips: "限制pdf、图片",
          accept: "application/pdf,image/*"
        },
        {
          id: 2,
          c1: "组建方案（签字盖章扫描上传）",
          c2: "是",
          moduleKey: "kjptzjfa",
          require: true,
          fileIds: [],
          fileLists: [],
          tips: "限制pdf、图片",
          accept: "application/pdf,image/*"
        },
        {
          id: 3,
          c1: "合作协议（签字盖章扫描上传，有共建单位的必备）",
          c2: "是",
          moduleKey: "kjpthzxy",
          require: true,
          fileIds: [],
          fileLists: [],
          tips: "限制pdf、图片",
          accept: "application/pdf,image/*"
        },
        {
          id: 4,
          c1: "牵头单位基础条件及成效表（上传excel表格）",
          c2: "是",
          moduleKey: "kjptqtdwjctj",
          require: true,
          fileIds: [],
          fileLists: [],
          tips: "限制pdf、excel",
          accept: "application/pdf,.xlsx,.xls"
        },
        {
          id: 5,
          c1: "其他",
          c2: "是",
          moduleKey: "kjptqt",
          require: true,
          fileIds: [],
          fileLists: [],
          tips: "限制pdf、图片",
          accept: "application/pdf,image/*"
        },
      ],
      projectFileColumns: [
        {
          colKey: "id",
          title: "序号",
          align: "center",
          width: 64
        },
        {
          colKey: "c1",
          title: "附件名称",
          align: "center",
        },

        {
          colKey: "c2",
          title: "是否必需",
          align: "center",
        },
        {
          colKey: "op",
          title: "操作",
          align: "left",
        },
      ],
      site_tag: import.meta.env.VITE_SITE_TAG,
      visible: true,
      currentDeptName: '',
      tabValue: "1",
      data: {
        name: "",
        platformCategory: "",
        address: "",
        postCode: "",
        buildDate: "",
        website: "",
        content: "",
        platformLeader: {
          name: "",
          sex: "",
          birthDate: "",
          education: "",
          duty: "",
          profTitId: "",
          profTit: "",
          majorName: "",
          telephone: "",
          phone: "",
          email: "",
        },
        platformLinker: {
          name: "",
          telephone: "",
          phone: "",
          email: "",
          facsimile: "",
        },
        constructionUnit: {
          name: "",
          sex: "",
          birthDate: "",
          education: "",
          duty: "",
          profTitId: "",
          profTit: "",
          majorName: "",
          telephone: "",
          phone: "",
          email: "",
          deptName: "",
          deptTelephone: "",
          deptFacsimile: "",
          deptAddress: "",
          deptPostCode: "",
        },

        platformBackground: {
          background: ""
        },
        platformMainTask: {
          mainTask: ""
        },
        platformBudget: {

        },
        platformEquipments: {

        },
        platformSafeguard: {

        }
      },
      projectCategoryOptions: []
    }
  },
  watch: {
    objId: {
      immediate: true,
      handler (val) {
        if (val) {
          this.getObj(val);
          this.getStepData()
          this.getUserInfo()
          this.getProfTitTreeSelect()
          this.getDeptTreeSelect()
        }
      }
    },
  },
  methods: {
    getProfTitTreeSelect () {
      return this.$api.system.profTit.list().then(response => {
        this.profTitOptions = this.handleTree(response.data, "id");
      }).catch((e) => {
        this.$message.error(e.toString());
      });
    },
    getDeptTreeSelect () {
      return this.$api.system.dept.treeSelectAllIn().then(response => {
        this.deptMenuOptions = response.data;
      }).catch((e) => {
        this.$message.error(e.toString());
      });
    },
    getUserInfo () {
      this.$api.system.user.getBaseInfo().then(response => {
        this.currentDeptName = response.data.dept.deptName;
      }).catch((e) => {
        this.$message.error(e.toString());
      });
    },
    async getObj () {
      // await Promise.all([this.getDeclareTree()]);
      try {
        let allDetail1 = await this.$api.kjpt.project.getAll(this.objId)
        // let member1 = await this.$api.kjpt.project.getPlatformMemberByType(this.objId, "1")
        // let member2 = await this.$api.kjpt.project.getPlatformMemberByType(this.objId, "2")
        // let allDetail2 = await this.$api.kjpt.project.getSafeguardByPlatformId(this.objId)
        getFiles(this.objId).then((res) => {
          const files = {}
          res.data.forEach((item) => {
            if (!files[item.moduleKey]) {
              files[item.moduleKey] = []
            }
            files[item.moduleKey].push({
              name: item.fileName,
              url: item.fullFilePath,
              id: item.id,
              filePath: item.filePath
            })
          })
          this.projectFileData.forEach((val, index) => {
            this.projectFileData[index].fileLists = files[val.moduleKey] || [];
            this.projectFileData[index].fileIds = files[val.moduleKey]?.map(val => val.id) || [];
          })
          // this.projectFileData[0].fileLists = files.kjptsysryb || [];
          // this.projectFileData[0].fileIds = files.kjptsysryb?.map(val => val.id) || [];

          // this.projectFileData[1].fileLists = files.kjptzjfa || [];
          // this.projectFileData[1].fileIds = files.kjptzjfa?.map(val => val.id) || [];

          // this.projectFileData[2].fileLists = files.kjpthzxy || [];
          // this.projectFileData[2].fileIds = files.kjpthzxy?.map(val => val.id) || [];

          // this.projectFileData[3].fileLists = files.kjptqtdwjctj || [];
          // this.projectFileData[3].fileIds = files.kjptqtdwjctj?.map(val => val.id) || [];

          // this.projectFileData[4].fileLists = files.kjptqt || [];
          // this.projectFileData[4].fileIds = files.kjptqt?.map(val => val.id) || [];
          console.log('------', this.projectFileData);

        }).catch((e) => {
          this.applyLoading = false;
          this.$message.error(e.toString());
        });
        Object.assign(this.data, allDetail1.data)
        // this.data.member1 = member1.data
        // this.data.member2 = member2.data
        // this.data.platformSafeguard.background = allDetail2.data?.safeguardCondition
        // console.log("allDetail2", allDetail2)
        console.log('this.data', this.data)
      } catch (e) {
        this.$message.error(e.toString());
      }

    },
    getStepData () {
      this.$api.kjpt.project.getPlatformMemberNoType(this.objId).then(response => {
        this.stepTwoData = response.data
      }).catch((e) => {
        this.$message.error(e.toString());
      });

      this.$api.kjpt.project.getByPlatformId(this.objId).then(response => {
        this.stepThreeData = response.data
      }).catch((e) => {
        this.$message.error(e.toString());
      });

      this.$api.kjpt.project.getManageOrgByPlatformId(this.objId).then(response => {
        this.stepFourData = response.data
      }).catch((e) => {
        this.$message.error(e.toString());
      });

      this.$api.kjpt.project.getManageScienceByPlatformId(this.objId).then(response => {
        this.stepFiveData = response.data;
      }).catch((e) => {
        this.$message.error(e.toString());
      });
    },
    getDeclareTree () {
      return this.$api.kjxm.project.planCategoryTree().then(response => {
        this.projectCategoryOptions = response.data;
      }).catch((e) => {
        this.$message.error(e.toString());
      });
    },
    closeDialog () {
      this.$emit("update:visible", false);
    },
  }
}
</script>

<style lang="less" scoped>
.t-tab-panel {
  padding: 10px;
  height: 100%;
}

.t-form__item {
  margin-bottom: 6px
}

.t-row {
  margin-bottom: 14px;
}

.step-card {
  height: 100%;
  margin-bottom: 14px;
}

.content_style {
  font-size: 12pt;
  font-family: 宋体;
  line-height: 1.5;
}

.t-tab-panel {
  padding: 10px;
}

.tab-panel {
  height: calc(65vh - 80px);
  overflow: scroll;
}

.tab-full-panel {
  height: calc(80vh - 80px);
  overflow: scroll;
}
</style>
